package com.ruoyi.web.controller.report;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.report.domain.CommunityNotice;
import com.ruoyi.report.service.ICommunityNoticeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 档案Controller
 *
 * @author mac
 * @date 2023-02-11
 */
@RestController
@RequestMapping("/report/notice")
public class CommunityNoticeController extends BaseController {
    @Autowired
    private ICommunityNoticeService communityNoticeService;

    /**
     * 查询档案列表
     */
    @PreAuthorize("@ss.hasPermi('report:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommunityNotice communityNotice) {
        startPage();
        List<CommunityNotice> list = communityNoticeService.selectCommunityNoticeList(communityNotice);
        return getDataTable(list);
    }

    /**
     * 导出档案列表
     */
    @PreAuthorize("@ss.hasPermi('report:notice:export')")
    @Log(title = "档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommunityNotice communityNotice) {
        List<CommunityNotice> list = communityNoticeService.selectCommunityNoticeList(communityNotice);
        ExcelUtil<CommunityNotice> util = new ExcelUtil<CommunityNotice>(CommunityNotice.class);
        util.exportExcel(response, list, "档案数据");
    }

    /**
     * 获取档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('report:notice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(communityNoticeService.selectCommunityNoticeById(id));
    }

    /**
     * 新增档案
     */
    @PreAuthorize("@ss.hasPermi('report:notice:add')")
    @Log(title = "档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityNotice communityNotice) {
        return toAjax(communityNoticeService.insertCommunityNotice(communityNotice));
    }

    /**
     * 修改档案
     */
    @PreAuthorize("@ss.hasPermi('report:notice:edit')")
    @Log(title = "档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommunityNotice communityNotice) {
        return toAjax(communityNoticeService.updateCommunityNotice(communityNotice));
    }

    /**
     * 删除档案
     */
    @PreAuthorize("@ss.hasPermi('report:notice:remove')")
    @Log(title = "档案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(communityNoticeService.deleteCommunityNoticeByIds(ids));
    }
}
